﻿using System;
using System.Linq;
using System.Windows;

using TraceView.Shared;

namespace TestClient
{
    public partial class MainWindow
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        private void OnWindowLoaded(object sender, RoutedEventArgs e)
        {
            Array severities = Enum.GetValues(typeof(Severity));
            foreach (Severity severity in severities)
                lstSeverities.Items.Add(severity);
            if (lstSeverities.Items.Count > 0)
                lstSeverities.SelectedIndex = 0;

            for (int i = 1; i <= 10; i++)
                lstRepetitions.Items.Add(i);
            lstRepetitions.SelectedIndex = 0;
        }

        private void OnSendMessage(object sender, RoutedEventArgs e)
        {
            ITraceService client = TraceServiceClient.Create();

            var selectedSeverity = (Severity)lstSeverities.SelectedItem;
            var repetitions = (int)lstRepetitions.SelectedItem;

            for (int i = 0; i < repetitions; i++)
            {
                var data = new TraceData
                {
                    ApplicationName = "Test Client",
                    Source = Environment.MachineName,
                    Severity = selectedSeverity,
                    UserName = Environment.UserName,
                    TimeStamp = DateTime.Now,
                };
                data.Categories.Add(selectedSeverity + " category");
                data.TraceObject = new TraceObject(typeof(string).FullName);
                data.TraceObject.DataItems.Add(new DataItem("Message", txtMessage.Text));
                client.Trace(data); 
            }
        }
    }
}